package doc2db.interfaces.mainWindow;

import java.awt.Font;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.JOptionPane;
import doc2db.Keey;
import doc2db.Launcher;
import doc2db.UserProp;
import doc2db.fileWorker.FileBeginer;
import doc2db.fileWorker.FileWorker;
import doc2db.interfaces.action.ChangeUserPropAction;
import doc2db.interfaces.action.templates.ChoiceTemplAction;
import doc2db.interfaces.action.CloseConectionAction;
import doc2db.interfaces.action.templates.CorectTemplatesAction;
import doc2db.interfaces.action.CreateConectionAction;
import doc2db.interfaces.action.DelTableAction;
import doc2db.interfaces.action.ExitAction;
import doc2db.interfaces.action.FontChooserAction;
import doc2db.interfaces.action.InsUpd.InsertAction;
import doc2db.interfaces.action.templates.NewTempletAction;
import doc2db.interfaces.action.SendUserDbQuery;
import doc2db.interfaces.action.ShowTableAction;
import doc2db.interfaces.action.TableListAction;
import doc2db.interfaces.action.InsUpd.UpdateAction;
import doc2db.interfaces.action.NewBookmarksAction;
import doc2db.interfaces.action.ToTreangleTabAction;
import doc2db.interfaces.action.templates.corectTemplInDbAction;
import doc2db.interfaces.action.createTable.CreateTableAction;
import doc2db.interfaces.action.open.OpenDir;
import doc2db.interfaces.action.open.OpenFile;
import doc2db.interfaces.action.save.SaveAction;
import doc2db.interfaces.action.save.SaveAsAction;
import doc2db.interfaces.elements.AboutBox;
import doc2db.interfaces.elements.AboutJava;
import doc2db.interfaces.printer.DocumentRenderer;
import java.io.File;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;

/**
 *
 * @author yuriy
 */
public class MyMenu {
    private Font s = UserProp.menuFont;
    private String toolFont =
            //"<html><table bgcolor=yellow border=1><tr><th><font size=\"4\" face=\"Verdana\">" +
            "<html>";
    private MyFrame mf;
    
    private JMenu menu = new JMenu("Меню");
    private JMenu UIMenu = new JMenu("Внешний вид");
    private JMenuItem openFile = new JMenuItem("Открыть файл");
    private JMenuItem openDir = new JMenuItem("Открыть папку");
    private JMenuItem save = new JMenuItem("Сохранить");
    private JMenuItem saveAs = new JMenuItem("Сохранить как");
    private final JCheckBoxMenuItem debug = new JCheckBoxMenuItem("Отладчик");
    private final JCheckBoxMenuItem sh = new JCheckBoxMenuItem("Сохранить файл");
    private JMenuItem print = new JMenuItem("Печать");
    private JMenuItem exit = new JMenuItem("Выход");

    private JMenu db = new  JMenu ("Работа с Б.Д.");
    private JMenuItem createMyCon = new JMenuItem("Cоздать короткое соеденение");
    private JMenuItem createNewCon = new JMenuItem("Cоздать полное соеденение");
    private JMenuItem closeCon = new JMenuItem("Закрыть соеденение с Б.Д.");
    private JMenu dbwork = new JMenu("Работа с Б.Д.");
    private JMenuItem tableList = dbwork.add("Список таблиц");
    private JMenuItem showTable = dbwork.add("Вывести таблицу");
    private JMenuItem delTable = dbwork.add("Удалить таблицу");
    private JMenuItem submitSql = dbwork.add("Выполнить sql запрос");
    private JMenuItem insert = dbwork.add("Внести данные в таблицу");
    private JMenuItem update = dbwork.add("Обнавить данные в таблице");
    private JMenuItem modetab = dbwork.add("Преобразовать данные в таблице");
    private JMenuItem createTable = dbwork.add("Создать таблицу");
    private JMenu bookmarks = new JMenu("Sql закладки");
    public  JMenu myBookmarks = this.getBookMarksMenu();
    private JMenuItem newBookmarks = new JMenuItem("Новая закладки");


    private JMenu correct = new JMenu("Правка");
    private JMenu correctPersParam = new JMenu("Правка параметров");
    private JMenuItem changeName = correctPersParam.add("Изменить ник");
    private JMenuItem changePswd = correctPersParam.add("Изменить пароль");
    private JMenuItem fonts = correct.add("Настройка фонтов");
    private JMenuItem createTempl = correct.add("Создать шаблон");
    private JMenuItem choiceTempl = correct.add("Выбор шаблона");
    private JMenuItem corectTempl = correct.add("Правка шаблона");
    private JMenuItem corectTemplInDb = correct.add("Правка шаблона в БД");
    private JMenu view = new JMenu("Вид");
    private JCheckBoxMenuItem v_all = new JCheckBoxMenuItem("Панель инструментов");
    private JCheckBoxMenuItem v_tableList = new JCheckBoxMenuItem("Список таблиц");
    private JCheckBoxMenuItem v_tabl = new JCheckBoxMenuItem("Вывести таблицу");
    private JCheckBoxMenuItem v_delTabl = new JCheckBoxMenuItem("удалить таблицу");
    private JCheckBoxMenuItem v_insert = new JCheckBoxMenuItem("Внести данные в таблицу");
    private JCheckBoxMenuItem v_update = new JCheckBoxMenuItem("Обнавить данные в таблице");
    private JCheckBoxMenuItem v_modetab = new JCheckBoxMenuItem("Преобразовать данные в таблице");
    private JCheckBoxMenuItem v_createTable = new JCheckBoxMenuItem("Создать таблицу");
    private JCheckBoxMenuItem v_createMyCon = new JCheckBoxMenuItem("Cоздать короткое соеденение");
    private JCheckBoxMenuItem v_createNewCon = new JCheckBoxMenuItem("Cоздать полное соеденение");
    private JCheckBoxMenuItem v_closeCon = new JCheckBoxMenuItem("Закрыть соеденение с Б.Д.");
    private JCheckBoxMenuItem v_createTempl = new JCheckBoxMenuItem("Создать шабон");
    private JCheckBoxMenuItem v_choiceTempl = new JCheckBoxMenuItem("Выбрать шаблон");
    private JCheckBoxMenuItem v_corectTempl = new JCheckBoxMenuItem("Правка шаблона");
    private JCheckBoxMenuItem v_corectTemplInDb = new JCheckBoxMenuItem("Правка шаблона в БД");
    private JCheckBoxMenuItem v_textDBSelects = new JCheckBoxMenuItem("Запросы к БД");
    private JCheckBoxMenuItem v_textOut = new JCheckBoxMenuItem("Сообщения");
    private JCheckBoxMenuItem v_textWeekendInformation = new JCheckBoxMenuItem("Выходные данные с БД");
    private JCheckBoxMenuItem v_textTemplete = new JCheckBoxMenuItem("Шаблон");
    private JCheckBoxMenuItem v_sqlSelectsArea = new JCheckBoxMenuItem("Поле ввода sql запросов");
    private JCheckBoxMenuItem v_fileEntryField = new JCheckBoxMenuItem("Поля ввода файла");

    private JCheckBoxMenuItem v_open = new JCheckBoxMenuItem("Открыть файл");
    private JCheckBoxMenuItem v_openDir = new JCheckBoxMenuItem("Открыть папку");
    private JCheckBoxMenuItem v_save = new JCheckBoxMenuItem("Сохранить");
    private JCheckBoxMenuItem v_saveAs = new JCheckBoxMenuItem("Сохранить как");
    
    private JMenu helpm = new JMenu("Справка");
    private JMenuItem help = new JMenuItem("Содержание");
    private JMenuItem on_linehelp = new JMenuItem("Веб-страница doc2db");
    private JMenuItem wikihelp = new JMenuItem("Помощь инциклопедии");
    private JMenuItem javaabout = new JMenuItem("О Java");
    private JMenuItem help_about = new JMenuItem("О программе");
    

    public MyMenu(MyFrame f){
        this.mf = f;
        this.setFont(this.s);
        this.setIcon();
        this.setToolTipeText();
        this.setAction();
        this.setEnableButton(false);
        this.setAccelerators();
    }

    JMenu getMenu(){
        menu.add(openFile);
        menu.add(openDir);
        menu.addSeparator();
        menu.add(save);
        menu.add(saveAs);
        menu.addSeparator();
        debug.setSelected(Keey.debug);
        sh.setSelected(Keey.sevaHtml);
//        menu.add(sh);
        menu.add(UIMenu);
        menu.add(print);
        menu.add(debug);
        menu.addSeparator();
        menu.add(exit);
        

        return menu;
    }

    JMenu getBd(){
        db.add(createMyCon);
        db.add(createNewCon);
        db.add(closeCon);
        db.add(dbwork);
        bookmarks.add(myBookmarks);
        bookmarks.add(newBookmarks);
        db.add(bookmarks);
        return db;
    }

    JMenu getCorrect(){
        createUIMenu();

        v_all.setSelected(UserProp.seeAll);
        v_tableList.setSelected(UserProp.tableList);
        v_tabl.setSelected(UserProp.showTable);
        v_delTabl.setSelected(UserProp.delTable);
        v_insert.setSelected(UserProp.insert);
        v_update.setSelected(UserProp.update);
        v_modetab.setSelected(UserProp.modetab);
        v_createTable.setSelected(UserProp.createTable);
        v_createMyCon.setSelected(UserProp.createMyCon);
        v_createNewCon.setSelected(UserProp.createNewCon);
        v_closeCon.setSelected(UserProp.closeCon);
        v_createTempl.setSelected(UserProp.createTempl);
        v_choiceTempl.setSelected(UserProp.choiceTempl);
        v_corectTempl.setSelected(UserProp.corectTempl);
        v_corectTemplInDb.setSelected(UserProp.corectTemplInDb);
        v_textDBSelects.setSelected(UserProp.textDBSelects);
        v_textOut.setSelected(UserProp.textOut);
        v_textWeekendInformation.setSelected(UserProp.textWeekendInformation);
        v_textTemplete.setSelected(UserProp.textTemplete);
        v_sqlSelectsArea.setSelected(UserProp.sqlSelectsArea);
        v_fileEntryField.setSelected(UserProp.fileEntryField);

        v_open.setSelected(UserProp.open);
        v_openDir.setSelected(UserProp.openDir);
        v_save.setSelected(UserProp.save);
        v_saveAs.setSelected(UserProp.saveAs);

        view.add(v_all);
        view.addSeparator();

        JMenu fileMn = new JMenu("Файл");
        fileMn.add(v_open);
        fileMn.add(v_openDir);
        fileMn.add(v_save);
        fileMn.add(v_saveAs);
        fileMn.setFont(s);
        view.add(fileMn);

        JMenu tmpltMn = new JMenu("Шаблон");
        tmpltMn.add(v_choiceTempl);
        tmpltMn.add(v_createTempl);
        tmpltMn.add(v_corectTempl);
        tmpltMn.add(v_corectTemplInDb);
        tmpltMn.setFont(s);
        view.add(tmpltMn);

        JMenu tblMn = new JMenu("Таблица");
        tblMn.add(v_tableList);
        tblMn.add(v_tabl);
        tblMn.add(v_delTabl);
        tblMn.add(v_insert);
        tblMn.add(v_update);
        tblMn.add(v_modetab);
        tblMn.add(v_createTable);
        tblMn.setFont(s);
        view.add(tblMn);

        JMenu conMn = new JMenu("Соединение");
        conMn.add(v_createMyCon);
        conMn.add(v_createNewCon);
        conMn.add(v_closeCon);
        conMn.setFont(s);
        view.add(conMn);

        JMenu pnlMn = new JMenu("Инструменты");
        pnlMn.add(v_fileEntryField);
        pnlMn.add(v_sqlSelectsArea);
        pnlMn.add(v_textWeekendInformation);
        pnlMn.add(v_textDBSelects);
        pnlMn.add(v_textTemplete);
        pnlMn.add(v_textOut);
        pnlMn.setFont(s);
        view.add(pnlMn);

        correct.add(correctPersParam);
        correct.add(UIMenu);
        correct.add(view);

        return correct;
    }

    JMenu getHelp () {
        helpm.add(help);
        helpm.addSeparator();
        helpm.add(on_linehelp);
        helpm.add(wikihelp);
        helpm.addSeparator();
        helpm.add(javaabout);
        helpm.add(help_about);
        return helpm;
    }


    public void setFont(Font f){
        //setMenuFont(menu, f);
        //setMenuFont(correct, f);
        //setMenuFont(db, f);
        //setMenuFont(helpm, f);

        menu.setFont(f);
        UIMenu.setFont(f);
        debug.setFont(f);
        sh.setFont(f);
        print.setFont(f);
        openFile.setFont(f);
        openDir.setFont(f);
        save.setFont(f);
        saveAs.setFont(f);
        exit.setFont(f);

        db.setFont(f);
        createMyCon.setFont(f);
        createNewCon.setFont(f);
        closeCon.setFont(f);
        dbwork.setFont(f);
        tableList.setFont(f);
        showTable.setFont(f);
        delTable.setFont(f);
        submitSql.setFont(f);
        insert.setFont(f);
        update.setFont(f);
        modetab.setFont(f);
        createTable.setFont(f);
        bookmarks.setFont(f);
        newBookmarks.setFont(f);

        correct.setFont(f);
        correctPersParam.setFont(f);
        changeName.setFont(f);
        changePswd.setFont(f);
        fonts.setFont(f);
        createTempl.setFont(f);
        choiceTempl.setFont(f);
        corectTempl.setFont(f);
        corectTemplInDb.setFont(f);
        view.setFont(f);
        v_all.setFont(f);
        v_tableList.setFont(f);
        v_tabl.setFont(f);
        v_delTabl.setFont(f);
        v_insert.setFont(f);
        v_update.setFont(f);
        v_modetab.setFont(f);
        v_createTable.setFont(f);
        v_createMyCon.setFont(f);
        v_createNewCon.setFont(f);
        v_closeCon.setFont(f);
        v_createTempl.setFont(f);
        v_choiceTempl.setFont(f);
        v_corectTempl.setFont(f);
        v_corectTemplInDb.setFont(f);
        v_textDBSelects.setFont(f);
        v_textOut.setFont(f);
        v_textWeekendInformation.setFont(f);
        v_textTemplete.setFont(f);
        v_fileEntryField.setFont(f);
        v_sqlSelectsArea.setFont(f);
        
        v_open.setFont(f);
        v_openDir.setFont(f);
        v_save.setFont(f);
        v_saveAs.setFont(f);

        helpm.setFont(f);
        help.setFont(f);
        on_linehelp.setFont(f);
        wikihelp.setFont(f);
        help_about.setFont(f);
        javaabout.setFont(f);
    }

    private void createUIMenu() {
        LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
        for (final javax.swing.UIManager.LookAndFeelInfo info : infos) {
            JMenuItem look = UIMenu.add(info.getName());
            look.addActionListener(new ActionListener() {

                String str = info.getClassName();

                @Override
                public void actionPerformed(ActionEvent arg0) {
                    try {
                        UIManager.setLookAndFeel(str);
                        UserProp.lookAndFeel = "" + str;
                        SwingUtilities.updateComponentTreeUI(mf);
                    } catch (Exception e) {
                        System.err.println("Can set LookAndFeel- " + str + ":" + e);
                    }
                }
            });
            look.setFont(s);
            look.setToolTipText(toolFont + info.getName());

            //String path = FileBeginer.resurse_resurseFolderMenu + Keey.sp + "applications-graphics_003.png";
            //look.setIcon(new ImageIcon(path));
        }
    }

    private void setIcon(){
        String str = FileBeginer.resurse_resurseFolderMenu+Keey.sp;
        UIMenu.setIcon(new ImageIcon(str+"lookAndFeel.jpg"));
        debug.setIcon(new ImageIcon(str + "debug.png"));
        sh.setIcon(new ImageIcon(str + "debug.jpg"));
        print.setIcon(new  ImageIcon(str + "Printer.png"));
        save.setIcon(new  ImageIcon(str + "save.png"));
        saveAs.setIcon(new  ImageIcon(str + "save-as.png"));
        openFile.setIcon(new  ImageIcon(str + "open.png"));
        openDir.setIcon(new  ImageIcon(str + "openfolder.png"));
        exit.setIcon(new  ImageIcon(str + "application-exit.png"));
        
        createMyCon.setIcon(new  ImageIcon(str + "createMyCon.png"));
        createNewCon.setIcon(new  ImageIcon(str + "createNewCon.png"));
        closeCon.setIcon(new  ImageIcon(str + "closeCon.png"));
        dbwork.setIcon(new  ImageIcon(str + "dbwork.png"));
        tableList.setIcon(new  ImageIcon(str + "view-restore.png"));
        showTable.setIcon(new  ImageIcon(str + "tabl.png"));
        delTable.setIcon(new  ImageIcon(str + "edit-delete_003.png"));
        submitSql.setIcon(new  ImageIcon(str + "document-send.png"));
        insert.setIcon(new  ImageIcon(str + "insert.png"));
        update.setIcon(new  ImageIcon(str + "update.png"));
        modetab.setIcon(new  ImageIcon(str + "modetab.png"));
        createTable.setIcon(new  ImageIcon(str + "createTable.png"));
        bookmarks.setIcon(new  ImageIcon(str + "bookmarks.png"));

        correctPersParam.setIcon(new  ImageIcon(str + "correctPersParam.png"));
        createTempl.setIcon(new  ImageIcon(str + "createTempl.png"));
        choiceTempl.setIcon(new  ImageIcon(str + "choiceTempl.png"));
        corectTempl.setIcon(new  ImageIcon(str + "corectTempl.png"));
        corectTemplInDb.setIcon(new  ImageIcon(str + "corectTemplInDb.png"));
        fonts.setIcon(new  ImageIcon(str + "fonts.png"));

        help.setIcon(new  ImageIcon(str + "help.png"));
        on_linehelp.setIcon(new  ImageIcon(str + "on-linehelp.png"));
        wikihelp.setIcon(new  ImageIcon(str + "wikihelp.png"));
        help_about.setIcon(new  ImageIcon(str + "help-about.png"));
        javaabout.setIcon(new  ImageIcon(str + "javaabout.png"));

        String path = "menu/";
        if (!new File(str + "lookAndFeel.jpg").exists()) {
            UIMenu.setIcon(Launcher.getIcon(path + "lookAndFeel.jpg"));
        }
        if (!new File(str + "debug.png").exists()) {
            debug.setIcon(Launcher.getIcon(path + "debug.png"));
        }
        if (!new File(str + "debug.jpg").exists()) {
            sh.setIcon(Launcher.getIcon(path + "debug.jpg"));
        }
        if (!new File(str + "Printer.png").exists()) {
            print.setIcon(Launcher.getIcon(path + "Printer.png"));
        }
        if (!new File(str + "save.png").exists()) {
            save.setIcon(Launcher.getIcon(path + "save.png"));
        }
        if (!new File(str + "save-as.png").exists()) {
            saveAs.setIcon(Launcher.getIcon(path + "save-as.png"));
        }
        if (!new File(str + "open.png").exists()) {
            openFile.setIcon(Launcher.getIcon(path + "open.png"));
        }
        if (!new File(str + "openfolder.png").exists()) {
            openDir.setIcon(Launcher.getIcon(path + "openfolder.png"));
        }
        if (!new File(str + "application-exit.png").exists()) {
            exit.setIcon(Launcher.getIcon(path + "application-exit.png"));
        }
        if (!new File(str + "createMyCon.png").exists()) {
            createMyCon.setIcon(Launcher.getIcon(path + "createMyCon.png"));
        }
        if (!new File(str + "createNewCon.png").exists()) {
            createNewCon.setIcon(Launcher.getIcon(path + "createNewCon.png"));
        }
        if (!new File(str + "closeCon.png").exists()) {
            closeCon.setIcon(Launcher.getIcon(path + "closeCon.png"));
        }
        if (!new File(str + "dbwork.png").exists()) {
            dbwork.setIcon(Launcher.getIcon(path + "dbwork.png"));
        }
        if (!new File(str + "view-restore.png").exists()) {
            tableList.setIcon(Launcher.getIcon(path + "view-restore.png"));
        }
        if (!new File(str + "tabl.png").exists()) {
            showTable.setIcon(Launcher.getIcon(path + "tabl.png"));
        }
        if (!new File(str + "edit-delete_003.png").exists()) {
            delTable.setIcon(Launcher.getIcon(path + "edit-delete_003.png"));
        }
        if (!new File(str + "document-send.png").exists()) {
            submitSql.setIcon(Launcher.getIcon(path + "document-send.png"));
        }
        if (!new File(str + "insert.png").exists()) {
            insert.setIcon(Launcher.getIcon(path + "insert.png"));
        }
        if (!new File(str + "update.png").exists()) {
            update.setIcon(Launcher.getIcon(path + "update.png"));
        }
        if (!new File(str + "modetab.png").exists()) {
            modetab.setIcon(Launcher.getIcon(path + "modetab.png"));
        }
        if (!new File(str + "createTable.png").exists()) {
            createTable.setIcon(Launcher.getIcon(path + "createTable.png"));
        }
        if (!new File(str + "bookmarks.png").exists()) {
            bookmarks.setIcon(Launcher.getIcon(path + "bookmarks.png"));
        }
        if (!new File(str + "correctPersParam.png").exists()) {
            correctPersParam.setIcon(Launcher.getIcon(path + "correctPersParam.png"));
        }
        if (!new File(str + "createTempl.png").exists()) {
            createTempl.setIcon(Launcher.getIcon(path + "createTempl.png"));
        }
        if (!new File(str + "choiceTempl.png").exists()) {
            choiceTempl.setIcon(Launcher.getIcon(path + "choiceTempl.png"));
        }
        if (!new File(str + "corectTempl.png").exists()) {
            corectTempl.setIcon(Launcher.getIcon(path + "corectTempl.png"));
        }
        if (!new File(str + "corectTemplInDb.png").exists()) {
            corectTemplInDb.setIcon(Launcher.getIcon(path + "corectTemplInDb.png"));
        }
        if (!new File(str + "fonts.png").exists()) {
            fonts.setIcon(Launcher.getIcon(path + "fonts.png"));
        }
        if (!new File(str + "help.png").exists()) {
            help.setIcon(Launcher.getIcon(path + "help.png"));
        }
        if (!new File(str + "on-linehelp.png").exists()) {
            on_linehelp.setIcon(Launcher.getIcon(path + "on-linehelp.png"));
        }
        if (!new File(str + "wikihelp.png").exists()) {
            wikihelp.setIcon(Launcher.getIcon(path + "wikihelp.png"));
        }
        if (!new File(str + "help-about.png").exists()) {
            help_about.setIcon(Launcher.getIcon(path + "help-about.png"));
        }
        if (!new File(str + "javaabout.png").exists()) {
            javaabout.setIcon(Launcher.getIcon(path + "javaabout.png"));
        }
    }

    /**
     * Adding tool typt text to menu iteams
     */
    private void setToolTipeText(){
        UIMenu.setToolTipText(toolFont + "выбор внешнего вида окна");
        debug.setToolTipText(toolFont + "включиь/выключить режим отладки");
        sh.setToolTipText(toolFont + "save/not html files");
        print.setToolTipText(toolFont + "Распечатать выходные данные");
        openFile.setToolTipText(toolFont + "Открыть файл");
        openDir.setToolTipText(toolFont + "Открыть папку");
        save.setToolTipText(toolFont + "Сохранить в html");
        saveAs.setToolTipText(toolFont + "Сохранить как ...");
        exit.setToolTipText(toolFont + "выход из программы");

        createMyCon.setToolTipText(toolFont + "создать соеденение, <br>" +
                                              "используя параметры <br>" +
                                              "пользователя, как в <br>" +
                                              "данной системе");
        createNewCon.setToolTipText(toolFont +"создать соеденение, <br>" +
                                              "используя другие <br>" +
                                              "параметры пользователя");
        closeCon.setToolTipText(toolFont + "закрыть соеденение с Б.Д.");
        dbwork.setToolTipText(toolFont + "работа с Б.Д.");
        tableList.setToolTipText(toolFont + "вывести список таблиц");
        showTable.setToolTipText(toolFont + "вывести таблицу");
        delTable.setToolTipText(toolFont + "удалить таблицу");
        submitSql.setToolTipText(toolFont + "выполнить sql запрос");
        insert.setToolTipText(toolFont + "внести данные в таблицу");
        update.setToolTipText(toolFont + "обнавить данные в таблицу");
        modetab.setToolTipText(toolFont + "Преобразовать данные в таблицу");
        createTable.setToolTipText(toolFont + "создать таблицу");

        correctPersParam.setToolTipText(toolFont + "Правка личных параметров");
        changeName.setToolTipText(toolFont + "Изменить системный псевдоним");
        changePswd.setToolTipText(toolFont + "Изменить системный пароль");
        fonts.setToolTipText(toolFont + "Изменить шрифты панели");
        createTempl.setToolTipText(toolFont + "Создать новый шаблон");
        choiceTempl.setToolTipText(toolFont + "Выбрать шаблон");
        corectTempl.setToolTipText(toolFont + "Настроить шаблон");
        corectTemplInDb.setToolTipText(toolFont + "Настроить шаблон в базе данных");
        view.setToolTipText(toolFont + "Элементы которые будут<br> " +
                                        "расположены на понели<br> " +
                                        "быстрого доступа");
        v_all.setToolTipText(toolFont + "Показывать ли саму панель");


        help.setToolTipText(toolFont + "Показать содержание <br>" +
                                       "оперативной справки");
        on_linehelp.setToolTipText(toolFont + "Открыть браузер и перейти<br>" +
                                              " на сайт doc2db");
        wikihelp.setToolTipText(toolFont + "Открыть браузер и перейти<br>" +
                                           " на сайт wik, к статье doc2db<br>");
        help_about.setToolTipText(toolFont + "Показать диалаговое окно с" +
                                             "информацией о программе doc2db");
        javaabout.setToolTipText(toolFont + "Показать диалаговое окно с<br>" +
                                             "информацией о программе Java");
    }

    /**
     * Adding action lisener to menu iteam
     */
    private void setAction(){
        save.addActionListener(new SaveAction(mf.pane.textWeekendInformation));
        saveAs.addActionListener(new SaveAsAction(mf.pane.textWeekendInformation));

        debug.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                Keey.debug = debug.isSelected();
                mf.toolBar.vmem.setVisible(Keey.debug);
                System.out.println("debug " + Keey.debug);
            }
        });
        sh.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                Keey.sevaHtml = sh.isSelected();
            }
        });
        print.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                DocumentRenderer docRend = new DocumentRenderer();
                docRend.print( mf.pane.textWeekendInformation);
            }
        });
        //ACTION
        openFile.addActionListener(new OpenFile(mf, mf.pane));
        openDir.addActionListener(new OpenDir(mf, mf.pane));
        exit.addActionListener(new ExitAction (mf));

        createMyCon.addActionListener(new CreateConectionAction(mf, false));
        createNewCon.addActionListener(new CreateConectionAction(mf, true));
        closeCon.addActionListener(new CloseConectionAction(mf));
        tableList.addActionListener(new TableListAction(mf.pane.textWeekendInformation,
                                                        mf.pane.textDBSelects));
        showTable.addActionListener(new ShowTableAction(mf.pane.textWeekendInformation,
                                                        mf.pane.textDBSelects));
        delTable.addActionListener(new DelTableAction(  mf.pane.textWeekendInformation,
                                                        mf.pane.textDBSelects));
        submitSql.addActionListener(new SendUserDbQuery(mf.pane.textWeekendInformation,
                                                        mf.pane.textDBSelects,
                                                        mf.pane.sqlToExe ));
        insert.addActionListener(new InsertAction(mf.pane.textWeekendInformation,
                                                       mf.pane.textDBSelects));
        update.addActionListener(new UpdateAction(mf.pane.textWeekendInformation,
                                                       mf.pane.textDBSelects));
        modetab.addActionListener(new ToTreangleTabAction(mf.pane.textWeekendInformation,
                                                       mf.pane.textDBSelects));
        createTable.addActionListener(new CreateTableAction(mf.pane.textDBSelects,
                                                       mf.pane.textWeekendInformation));
        newBookmarks.addActionListener(new NewBookmarksAction(mf));


        changeName.addActionListener(new ChangeUserPropAction(1));
        changePswd.addActionListener(new ChangeUserPropAction(2));
        fonts.addActionListener(new FontChooserAction(mf));
        createTempl.addActionListener(new NewTempletAction());
        ChoiceTemplAction a = new ChoiceTemplAction(null, null);
        a.setTextArea(mf.pane.textTemp, mf.pane.textMetaTemp);
        choiceTempl.addActionListener(a);
        corectTempl.addActionListener(new CorectTemplatesAction());
        corectTemplInDb.addActionListener(new corectTemplInDbAction(null, null));
        v_all.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.seeAll = v_all.isSelected();
                mf.toolBar.setVisible(UserProp.seeAll);
            }
        });
        v_tableList.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.tableList = v_tableList.isSelected();
                mf.toolBar.tablList.setVisible(UserProp.tableList);
                mf.toolBar.strukttablList.setVisible(UserProp.tableList);
            }
        });
        v_tabl.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.showTable = v_tabl.isSelected();
                mf.toolBar.tabl.setVisible(UserProp.showTable);
                mf.toolBar.strukttabl.setVisible(UserProp.showTable);
            }
        });
        v_delTabl.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.delTable = v_delTabl.isSelected();
                mf.toolBar.delTabl.setVisible(UserProp.delTable);
                mf.toolBar.struktdelTabl.setVisible(UserProp.delTable);
            }
        });
        v_insert.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.insert = v_insert.isSelected();
                mf.toolBar.insert.setVisible(UserProp.insert);
                mf.toolBar.struktinsert.setVisible(UserProp.insert);
            }
        });
        v_update.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.update = v_update.isSelected();
                mf.toolBar.update.setVisible(UserProp.update);
                mf.toolBar.struktupdate.setVisible(UserProp.update);
            }
        });
        v_modetab.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.modetab = v_modetab.isSelected();
                mf.toolBar.modetab.setVisible(UserProp.modetab);
                mf.toolBar.struktmodetab.setVisible(UserProp.modetab);
            }
        });
        v_createTable.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.createTable = v_createTable.isSelected();
                mf.toolBar.createTable.setVisible(UserProp.createTable);
                mf.toolBar.struktcreateTable.setVisible(UserProp.createTable);
            }
        });
        v_createMyCon.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.createMyCon = v_createMyCon.isSelected();
                mf.toolBar.createMyCon.setVisible(UserProp.createMyCon);
                mf.toolBar.struktcreateMyCon.setVisible(UserProp.createMyCon);
            }
        });
        v_createNewCon.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp .createNewCon= v_createNewCon.isSelected();
                mf.toolBar.createNewCon.setVisible(UserProp.createNewCon);
                mf.toolBar.struktcreateNewCon.setVisible(UserProp.createNewCon);
            }
        });
        v_closeCon.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.closeCon = v_closeCon.isSelected();
                mf.toolBar.closeCon.setVisible(UserProp.closeCon);
                mf.toolBar.struktcloseCon.setVisible(UserProp.closeCon);
            }
        });
        v_createTempl.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.createTempl = v_createTempl.isSelected();
                mf.toolBar.createTempl.setVisible(UserProp.createTempl);
                mf.toolBar.struktcreateTempl.setVisible(UserProp.createTempl);
            }
        });
        v_choiceTempl.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.choiceTempl = v_choiceTempl.isSelected();
                mf.toolBar.choiceTempl.setVisible(UserProp.choiceTempl);
                mf.toolBar.struktchoiceTempl.setVisible(UserProp.choiceTempl);
            }
        });
        v_corectTempl.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.corectTempl = v_corectTempl.isSelected();
                mf.toolBar.corectTempl.setVisible(UserProp.corectTempl);
                mf.toolBar.struktcorectTempl.setVisible(UserProp.corectTempl);
            }
        });
        v_corectTemplInDb.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.corectTemplInDb = v_corectTemplInDb.isSelected();
                mf.toolBar.corectTemplInDb.setVisible(UserProp.corectTemplInDb);
                mf.toolBar.struktcorectTemplInDb.setVisible(UserProp.corectTemplInDb);
            }
        });

        v_open.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.open = v_open.isSelected();
                mf.toolBar.open.setVisible(UserProp.open);
                mf.toolBar.strukopen.setVisible(UserProp.open);
            }
        });
        v_openDir.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.openDir = v_openDir.isSelected();
                mf.toolBar.openDir.setVisible(UserProp.openDir);
                mf.toolBar.strukopenDir.setVisible(UserProp.openDir);
            }
        });
        v_save.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.save = v_save.isSelected();
                mf.toolBar.save.setVisible(UserProp.save);
                mf.toolBar.struksave.setVisible(UserProp.save);
            }
        });
        v_saveAs.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.saveAs = v_saveAs.isSelected();
                mf.toolBar.saveAs.setVisible(UserProp.saveAs);
                mf.toolBar.struksaveAs.setVisible(UserProp.saveAs);
            }
        });

        v_textDBSelects.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.textDBSelects = v_textDBSelects.isSelected();
                mf.pane.textDBSelectsSetVisible(UserProp.textDBSelects);
            }
        });
        v_textWeekendInformation.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.textWeekendInformation = v_textWeekendInformation.isSelected();
                mf.pane.textWeekendInformationSetVisible(UserProp.textWeekendInformation);
            }
        });
        v_textTemplete.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.textTemplete = v_textTemplete.isSelected();
                mf.pane.textTempleteSetVisible(UserProp.textTemplete);
            }
        });
        v_textOut.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.textOut = v_textOut.isSelected();
                mf.pane.textOutSetVisible(UserProp.textOut);
            }
        });
        v_fileEntryField.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.fileEntryField = v_fileEntryField.isSelected();
                mf.pane.textPnlFileEntrySetVisible(UserProp.fileEntryField);
            }
        });
        v_sqlSelectsArea.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                UserProp.sqlSelectsArea = v_sqlSelectsArea.isSelected();
                mf.pane.textSqlSelectsSetVisible(UserProp.sqlSelectsArea);
            }
        });


        help.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(mf, "sorry bat suport is available");
            }
        });
        on_linehelp.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                Keey.openBrowser("http://test1.inf.ua/index.html");
            }
        });
        wikihelp.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                Keey.openBrowser("http://ru.wikipedia.org/wiki/Doc2db");
            }
        });
        help_about.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                AboutBox aboutBox = new AboutBox(mf);
                aboutBox.setLocationRelativeTo(null);
                aboutBox.setVisible(true);
            }
        });
        javaabout.addActionListener(new ActionListener() {
            @Override public void actionPerformed(ActionEvent e) {
                AboutJava aboutJava = new AboutJava(mf);
                aboutJava.setLocationRelativeTo(mf);
                aboutJava.setVisible(true);
            }
        });

    }

    private void setAccelerators () {
        int ctrl = InputEvent.CTRL_MASK;
        int shft = InputEvent.SHIFT_MASK;
        exit.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_Q, ctrl + shft));

        save.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_S,ctrl));
        saveAs.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_S, ctrl + shft));

        openFile.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_O,ctrl));
        openDir.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_O, ctrl + shft));

        print.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_P,ctrl));

        tableList.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_L,ctrl));
        showTable.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_T,ctrl));
        delTable.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_D,ctrl));
        insert.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_I,ctrl));
        update.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_U,ctrl));
        modetab.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_M,ctrl));

        createTempl.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_C,ctrl));
        choiceTempl.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_G,ctrl));
        corectTempl.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_G, ctrl + shft));
        corectTemplInDb.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_G, ctrl + InputEvent.ALT_MASK));

        help.setAccelerator(KeyStroke.getKeyStroke(
                KeyEvent.VK_F1, 0));

    }

    public void setEnableButton(boolean b){
        tableList.setEnabled(b);
        showTable.setEnabled(b);
        delTable.setEnabled(b);
        closeCon.setEnabled(b);
        submitSql.setEnabled(b);
        insert.setEnabled(b);
        update.setEnabled(b);
        modetab.setEnabled(b);
        createTable.setEnabled(b);
        bookmarks.setEnabled(b);
    }

    private JMenu getBookMarksMenu() {
        JMenu myMenu = new JMenu("мои закладки");
        myMenu.setFont(s);
        myMenu.setIcon(new  ImageIcon(FileBeginer.resurse_resurseFolderMenu+Keey.sp
                + "myBookmarks.png"));
        String fileName = FileBeginer.resurse_users_usersFolder
                + Keey.sp + UserProp.user + Keey.sp + "bookmarks.ini";
        final String [][] str = FileWorker.getProprtyList(fileName);
        if(str == null)
            return myMenu;
        for (int i = 0; i < str.length; i++) {
            final String s2 = str[i][1];
            JMenuItem m = myMenu.add(new AbstractAction(str[i][0]) {
                @Override public void actionPerformed(ActionEvent e) {
                    mf.pane.sqlToExe.setText(s2);
                    new SendUserDbQuery(mf.pane.textWeekendInformation,
                            mf.pane.textDBSelects, mf.pane.sqlToExe).actionPerformed(null);
                }
            });
            m.setFont(s);
            m.setToolTipText("<html><table width=400><tr><td> " + s2 );
        }

        return myMenu;
    }

    public void addbookMarks(String name, String sql){
        final String s2 = "" + sql;
        JMenuItem m = myBookmarks.add(new AbstractAction(name) {
            @Override public void actionPerformed(ActionEvent e) {
                mf.pane.sqlToExe.setText(s2);
                new SendUserDbQuery(mf.pane.textWeekendInformation,
                        mf.pane.textDBSelects, mf.pane.sqlToExe).actionPerformed(null);
            }
        });
        m.setFont(s);
        m.setToolTipText("<html><table width=400><tr><td> " + sql);
    }
}
